package com.zmn.oms.services.impl.wallservitem;

import com.zmn.base.plat.engine.common.constant.PlatEngineConsts;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.oms.model.entity.wallservitem.WallServItem;
import com.zmn.oms.model.entity.wallservitem.WallServItemQuery;
import com.zmn.oms.persistence.interfaces.wallservitem.WallServItemDao;
import com.zmn.oms.services.interfaces.wallservitem.WallServItemService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 墙面报价-工艺接口实现类
 *
 * @author chengguang
 * @since 2022/05/25 14:10
 */
@Slf4j
@Service
public class WallServItemServiceImpl implements WallServItemService {

    private static final String TAG = "墙面报价-工艺基础服务接口";

    @Resource
    private WallServItemDao wallServItemDao;

    @Override
    public WallServItem findById(Long relateId) {
        if (Objects.isNull(relateId)) {
            log.error("[{}],根据id查询数据relateId为null", TAG);
            return null;
        }
        return wallServItemDao.findById(relateId);
    }

    @Override
    public Integer findMaxSort() {
        return wallServItemDao.findMaxSort();
    }

    @Override
    public List<WallServItem> listByIds(List<Long> relateIds) {
        if (CollectionUtils.isEmpty(relateIds)) {
            log.error("[{}],按条件查询数据,relateIds为null", TAG);
            return Collections.emptyList();
        }
        return wallServItemDao.listByIds(relateIds);
    }

    @Override
    public List<WallServItem> listByQuery(WallServItemQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return Collections.emptyList();
        }
        return wallServItemDao.listByQuery(query);
    }

    @Override
    public List<WallServItem> listPageByQuery(WallServItemQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return Collections.emptyList();
        }
        Integer count = countByQuery(query);
        query.setTotalCount(count);
        if (Objects.equals(count, PlatEngineConsts.NONE)) {
            return new ArrayList<>();
        }
        return wallServItemDao.listPageByQuery(query);
    }

    @Override
    public Integer countByQuery(WallServItemQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return wallServItemDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(WallServItem wallServItem) {
        if (Objects.isNull(wallServItem.getRelateId())) {
            log.error("[{}],根据id修改数据,wallServItem为null", TAG);
            return null;
        }
        return wallServItemDao.updateByKey(wallServItem);
    }

    @Override
    public void updateStatusBatch(List<Long> ids, Integer status, String operator) {
        if (!Objects.equals(status, PlatEngineConsts.NO) && !Objects.equals(status, PlatEngineConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        wallServItemDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert(WallServItem wallServItem) {
        if (Objects.isNull(wallServItem)) {
            log.error("[{}],新增数据,wallServItem为null", TAG);
            return null;
        }
        return wallServItemDao.insert(wallServItem);
    }

    @Override
    public void insertBatch(List<WallServItem> list) {
        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        wallServItemDao.insertBatch(list);
    }

    @Override
    public Integer deleteByKey(Long relateId) {
        if (Objects.isNull(relateId)) {
            log.error("[{}],根据id删除数据,relateId为null", TAG);
            return null;
        }
        return wallServItemDao.deleteByKey(relateId);
    }

    @Override
    public Integer deleteByWorkId(Long workId) {
        if (Objects.isNull(workId)) {
            log.error("[{}],根据id删除数据,workId为null", TAG);
            return null;
        }
        return wallServItemDao.deleteByWorkId(workId);
    }

}